{include file="public/layout" /}
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit;min-width:auto;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="shop_product/left" /}
<div class="page min-hg-c-10" style="min-width:auto;margin-left:100px;">
    <div class="flexigrid">
        <div class="mDiv pt0">
            <div class="ftitle">
                <div class="fbutton"><a href="JavaScript:void(0);" onclick="addLabelTypes();"><div class="add"><span><i class="layui-icon layui-icon-addition"></i>新增商品标签</span></div></a></div>
            </div>
        </div>
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%">
                    <thead>
                        <tr>
                            <th abbr="article_time" axis="col4" class="w40"> <div class="tc">ID</div> </th>
                            <th abbr="article_time" axis="col4" class="w200"> <div class="tl" style="padding-left: 20px;">商品标签</div> </th>
                            <th abbr="article_time" axis="col4"> <div style="padding-left: 15px;"><!-- 描述 --></div> </th>
                            <th abbr="article_time" axis="col4" class="w80"> <div class="tc">操作</div> </th>
                            <th abbr="article_time" axis="col4" class="w60"> <div class="tc">排序</div> </th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto; min-height: auto;">
            <form id="PostForm">
                <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                    <table style="width: 100%">
                        <tbody id="Template">
                        {empty name="list"}
                            <tr> <div class=""> <div class="no_pic"><img src="__SKIN__/images/null-data.png"></div> </div> </tr>
                        {else/}
                            {foreach name="list" item="vo" key="k" }
                            <tr class="tr" id="tr_{$vo.types_id}">
                                <td  class="operation"> 
                                    <div class="w40 tc">
                                    {$vo.types_id}
                                    </div> 
                                </td>
                                <td> 
                                    <div class="w200 tc">
                                        <input type="text" name="types_names[]" value="{$vo.types_names}" onchange="changeTableVal('label_types', 'types_id', '{$vo.types_id}', 'types_names', this);" class="tl">
                                    </div>
                                </td>
                                <td style="width: 100%">
                                    <div style="padding-left: 10px;">
                                        <!-- <input type="text" name="types_intro[]" value="{$vo.types_intro}" onchange="changeTableVal('label_types', 'types_id', '{$vo.types_id}', 'types_intro', this);" style="width: 90%;"> -->
                                    </div>
                                </td>
                                <td  class="operation">
                                    <div class="w80 tc">
                                        {eq name="'ShopProduct@ajaxLabelTypesDel'|is_check_access" value="1"}
                                        <a class="btn red" href="javascript:void(0);" data-types_id="{$vo.types_id}" onclick="delLabelTypes(this, true);">删除</a>
                                        {/eq}
                                    </div>
                                </td>
                                <td class="sort">
                                    <div class="w60 tc">
                                        <input type="text" onchange="changeTableVal('label_types', 'types_id', '{$vo.types_id}', 'sort_order', this);" size="4" value="{$vo.sort_order}" class="tc" onkeyup="this.value=this.value.replace(/[^\d]/g,'');" onpaste="this.value=this.value.replace(/[^\d]/g,'')"/>
                                    </div>
                                </td>
                            </tr>
                            {/foreach}
                        {/empty}
                        </tbody>
                    </table>
                </div>
            </form>
        </div>
        {notempty name="list"}
        <div class="tDiv">
            <div class="tDiv2">
                {include file="public/page" /}
            </div>
            <div style="clear:both"></div>
        </div>
        {/notempty}
    </div>
</div>

<script type="text/javascript">
    // 标签类型值(商品商品标签)
    var types_value = 1;

    // 新增空的商品标签
    function addLabelTypes() {
        var numbers = $('#Template').find('tr').length + 1;
        $.ajax({
            type: 'post',
            url : "{:url('ShopProduct/ajaxLabelTypesAdd')}",
            data: {types_value: types_value, _ajax: 1},
            dataType: 'json',
            success: function(res) {
                if (1 === parseInt(res.code)) {
                    var AddHtml = [];
                    AddHtml += 
                        '<tr class="tr" id="tr_'+res.data.types_id+'">'+
                            '<td  class="operation"> <div class="w40 tc"> '+numbers+' </div> </td>' + 
                            '<td>'+
                                '<div class="w200 tc">'+
                                    '<input type="text" name="types_names[]" value="' + res.data.types_names + '" onchange="changeTableVal(\'label_types\', \'types_id\', \'' + res.data.types_id + '\', \'types_names\', this);">'+
                                '</div>'+
                            '</td>'+
                            '<td style="width: 100%">'+
                                '<div style="padding-left: 10px;">'+
                                    // '<input type="text" name="types_intro[]" value="' + res.data.types_intro + '" onchange="changeTableVal(\'label_types\', \'types_id\', \'' + res.data.types_id + '\', \'types_intro\', this);" style="width: 90%;">'+
                                '</div>'+
                            '</td>'+
                            '<td class="">'+
                                '<div class="w80 tc">'+
                                    '<a class="btn red" href="javascript:void(0);" data-types_id="' + res.data.types_id + '" onclick="delLabelTypes(this, false);">删除</a>'+
                                '</div>'+
                            '</td>'+
                            '<td class="sort">'+
                                '<div class="w60 tc">'+
                                    '<input type="text" onchange="changeTableVal(\'label_types\', \'types_id\', \'' + res.data.types_id + '\', \'sort_order\', this);" size="4" value="100"/>'+
                                '</div>'+
                            '</td>'+
                        '</tr>';
                    $('#Template').append(AddHtml);
                } else {
                    layer.alert(res.msg, {icon: 2, title: false});
                }
            }
        });
    }

    // 删除指定商品标签
    function delLabelTypes(obj, isConfirm) {
        var types_id = $(obj).attr('data-types_id');
        if (isConfirm) {
            layer.confirm('确认删除该商品标签？', {
                area: ['480px', '190px'],
                move: false,
                title: '提示',
                shade: layer_shade,
                btnAlign:'r',
                closeBtn: 3,
                btn: ['确定','取消'] ,//按钮
                success: function () {
                    $(".layui-layer-content").css('text-align', 'left');
                }
            }, function() {
                // 执行删除指定商品标签
                executeDelLabelTypes(types_id);
            }, function(index) {
                layer.close(index);
            });
        } else {
            // 执行删除指定商品标签
            executeDelLabelTypes(types_id);
        }
    }

    // 执行删除指定商品标签
    function executeDelLabelTypes(types_id) {
        $.ajax({
            type: 'post',
            url : "{:url('ShopProduct/ajaxLabelTypesDel')}",
            data: {types_id: types_id, types_value: types_value, _ajax: 1},
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    $('#tr_' + types_id).remove();
                } else {
                    layer.alert(res.msg, {icon: 2, title: false});
                }
            }
        });
    }
</script>

{include file="public/footer" /}